// 这是一个链表
export class MNode {
    type = ''; // 节点类型
    parent = null;
    firstChild = null;
    lastChild = null;
    prev = null;
    next = null;
    unlink() {
        if (this.prev) {
            this.prev.next = this.next;
        } else if (this.parent) {
            this.parent.firstChild = this.next;
        }
        if (this.next) {
            this.next.prev = this.prev;
        } else if (this.parent) {
            this.parent.lastChild = this.prev;
        }
        this.parent = null;
        this.next = null;
        this.prev = null;
    }
    // 添加子元素
    appendChild(mnode) {
        mnode.unlink();
        mnode.parent = this;
        if (this.lastChild) {
            this.lastChild.next = mnode;
            mnode.prev = this.lastChild;
            this.lastChild = mnode;
        } else {
            this.firstChild = this.lastChild = mnode;
        }
    }
    // 在后面添加兄弟元素
    insertAfter(mnode) {
        mnode.unlink();
        mnode.next = this.next;
        if (mnode.next) {
            mnode.next.prev = mnode;
        }
        mnode.prev = this;
        this.next = mnode;
        mnode.parent = this.parent;
        if (!mnode.next && mnode.parent) {
            mnode.parent.lastChild = mnode;
        }
    }

}
export default MNode